﻿// Fill out your copyright notice in the Description page of Project Settings.


#include "AIController/BossAIController.h"

#include "BehaviorTree/BlackboardComponent.h"
#include "Character/BossCharacter.h"
#include "Kismet/GameplayStatics.h"


// Sets default values
ABossAIController::ABossAIController()
{
	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
}

// Called when the game starts or when spawned
void ABossAIController::BeginPlay()
{
	Super::BeginPlay();
}

// Called every frame
void ABossAIController::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
}

void ABossAIController::OnPossess(APawn* InPawn)
{
	Super::OnPossess(InPawn);
	ABossCharacter* boss = Cast<ABossCharacter>(InPawn);
	if (boss)
	{
		RunBehaviorTree(boss->BehaviorTree);
		// 设置行为树黑板里的参数
		UBlackboardComponent* BlackboardComponent = GetBlackboardComponent();
		ACharacter* PlayerPawn = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
		if (BlackboardComponent)
		{
			if (PlayerPawn)
			{
				//Debug::printLog("set blackboard playerPawn");
				BlackboardComponent->SetValueAsObject(FName("PlayerPawn"), PlayerPawn);
			}
		}
	}
	
}

void ABossAIController::SetAIDamage()
{
	// 设置行为树黑板里的参数
	UBlackboardComponent* BlackboardComponent = GetBlackboardComponent();
	APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
	if (BlackboardComponent)
	{
		if (PlayerPawn)
		{
			//Debug::printLog("set blackboard playerPawn");
			BlackboardComponent->SetValueAsObject(FName("PlayerPawn"), PlayerPawn);
		}
	}
	// Debug::printLog("ai controller do damage");
	// UBlackboardComponent* BlackboardComponent = GetBlackboardComponent();
	BlackboardComponent->SetValueAsBool(FName("IsDamage"), true);
}
